// MSP430 向 STM8L 靠拢(兼容性适配)
#include <intrinsics.h>
#include <ysizet.h>


typedef unsigned long 	uint32_t;
typedef unsigned int 	uint16_t;
typedef unsigned char	uint8_t;

typedef long	s32;
typedef int 	s16;
typedef char	s8;

typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus, BitStatus, BitAction;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;

typedef volatile uint8_t GPIO_TypeDef;
typedef uint8_t GPIO_Pin_TypeDef;

// 为了解决有很多 GPIO 端口没有 EXTI 中断能力，导致 GPIO 接口无法统一的问题，定义一个不存在的寄存器
extern uint8_t _GPIO_REG_Dummy;

#ifndef P3IFG
#define P3IE	_GPIO_REG_Dummy
#define P3IES	_GPIO_REG_Dummy
#define P3IFG	_GPIO_REG_Dummy
#endif

#define GPIO_Pin_0		GPIO_PIN_0
#define GPIO_Pin_1		GPIO_PIN_1
#define GPIO_Pin_2		GPIO_PIN_2
#define GPIO_Pin_3		GPIO_PIN_3
#define GPIO_Pin_4		GPIO_PIN_4
#define GPIO_Pin_5		GPIO_PIN_5
#define GPIO_Pin_6		GPIO_PIN_6
#define GPIO_Pin_7		GPIO_PIN_7

#define GPIO_Mode_In_FL_No_IT     	GPIO_MODE_IN_FL_NO_IT
#define GPIO_Mode_In_PU_No_IT     	GPIO_MODE_IN_PU_NO_IT
#define GPIO_Mode_In_FL_IT        	GPIO_MODE_IN_FL_IT
#define GPIO_Mode_In_PU_IT        	GPIO_MODE_IN_PU_IT
#define GPIO_Mode_Out_OD_Low_Fast 	GPIO_MODE_OUT_OD_LOW_FAST
#define GPIO_Mode_Out_PP_Low_Fast 	GPIO_MODE_OUT_PP_LOW_FAST
#define GPIO_Mode_Out_OD_Low_Slow 	GPIO_MODE_OUT_OD_LOW_SLOW
#define GPIO_Mode_Out_PP_Low_Slow 	GPIO_MODE_OUT_PP_LOW_SLOW
#define GPIO_Mode_Out_OD_HiZ_Fast 	GPIO_MODE_OUT_OD_HIZ_FAST
#define GPIO_Mode_Out_PP_High_Fast	GPIO_MODE_OUT_PP_HIGH_FAST
#define GPIO_Mode_Out_OD_HiZ_Slow 	GPIO_MODE_OUT_OD_HIZ_SLOW
#define GPIO_Mode_Out_PP_High_Slow	GPIO_MODE_OUT_PP_HIGH_SLOW

#define CLK_Peripheral_I2C		CLK_PERIPHERAL_I2C
#define CLK_Peripheral_SPI		CLK_PERIPHERAL_SPI
#define CLK_Peripheral_USART1	CLK_PERIPHERAL_UART1
#define CLK_Peripheral_USART2	CLK_PERIPHERAL_UART2
#define CLK_Peripheral_USART3	CLK_PERIPHERAL_UART3
#define CLK_Peripheral_TIM6		CLK_PERIPHERAL_TIMER6
#define CLK_Peripheral_TIM4		CLK_PERIPHERAL_TIMER4
#define CLK_Peripheral_TIM5		CLK_PERIPHERAL_TIMER5
#define CLK_Peripheral_TIM2		CLK_PERIPHERAL_TIMER2
#define CLK_Peripheral_TIM3		CLK_PERIPHERAL_TIMER3
#define CLK_Peripheral_TIM1		CLK_PERIPHERAL_TIMER1
#define CLK_Peripheral_AWU		CLK_PERIPHERAL_AWU
#define CLK_Peripheral_ADC		CLK_PERIPHERAL_ADC
#define CLK_Peripheral_CAN		CLK_PERIPHERAL_CAN

#define EXTI_Trigger_TypeDef	EXTI_Sensitivity_TypeDef

#define EXTI_Trigger_Falling_Low	EXTI_SENSITIVITY_FALL_LOW
#define EXTI_Trigger_Rising			EXTI_SENSITIVITY_RISE_ONLY
#define EXTI_Trigger_Falling		EXTI_SENSITIVITY_FALL_ONLY
#define EXTI_Trigger_Rising_Falling	EXTI_SENSITIVITY_RISE_FALL

typedef uint8_t USART_WordLength_TypeDef;
typedef uint8_t USART_StopBits_TypeDef;
typedef uint8_t USART_Parity_TypeDef;

#define USART_WordLength_8b		UART1_WORDLENGTH_8D
#define USART_StopBits_1		UART1_STOPBITS_1
#define USART_Parity_No			UART1_PARITY_NO

#define FLASH_PROGRAM_START_PHYSICAL_ADDRESS	FLASH_PROG_START_PHYSICAL_ADDRESS
#define FLASH_PROGRAM_END_PHYSICAL_ADDRESS		FLASH_PROG_END_PHYSICAL_ADDRESS

#define FLASH_ProgramTime_Standard	FLASH_PROGRAMTIME_STANDARD
#define FLASH_ProgramMode_Standard	FLASH_PROGRAMMODE_STANDARD
#define FLASH_MemType_Program		FLASH_MEMTYPE_PROG
#define FLASH_MemType_Data			FLASH_MEMTYPE_DATA
